package com.example.blog_system.dao;

import com.example.blog_system.model.domain.Article;
import com.example.blog_system.model.domain.Statistic;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StatisticMapper {
    @Insert("insert into t_statistic(article_id,hits,comments_num) values(#{id},0,0)")
    public void addStatistic(Article article);

    @Select("select * from t_statistic where article_id=#{articleId}")
    public Statistic selectStatisticWithArticleId(Integer articleId);

    @Update("update t_statistic set hits=#{hits}"+"where article_id=#{articleId}")
    public void updateArticleHitsWithId(Statistic statistic);

    @Update("update t_statistic set comments_num=#{commentsNum}"+"where article_id=#{articleId}")
    public void updateArticleCommentsWithId(Statistic statistic);

    @Delete("delete from t_statistic where article_id=#{aid}")
    public void deleteStatisticWithId(int aid);

    @Select("select * from t_statistic where hits!='0' "+"order by hits desc,comments_num desc")
    public List<Statistic> getStatistic();

    @Select("select sum(hits) from t_statistic")
    public long getTotalVisit();

    @Select("select sum(comments_num) from t_statistic")
    public long getTotalComment();
}
